﻿using System;
using System.Linq;
//using GpsGate.iTrac;
using System.Text;
using System.Messaging;
using System.Xml.Serialization;
using System.IO.Ports;


namespace Server
{
    class Program
    {
        public class Payment
        {
            public string Payor, Payee;
            public int Amount;
            public string DueDate;
        }

        public class Person
        {
            public string FirstName
            {
                get;
                set;
            }
            public string LastName
            {
                get;
                set;
            }
        }

        const string queueName = @".\private$\smartcar";

        static void Main(string[] args)
        {

          //  // Cut
          //  byte[] m_arrByte = new byte[] { 0x29, 0x29, 0x80, 0x00, 0x28, 0x37, 0x18, 0x86, 0x54, 0x12, 0x07, 0x29, 0x18, 0x03, 0x43, 0x01, 0x00, 0x33, 0x35, 0x88, 0x42, 0x64, 0x76, 0x00, 0x00, 0x01, 0x89, 0xFF, 0xFF, 0x00, 0x00, 0x82, 0xFC, 0x00, 0x00, 0x00, 0x0F, 0x64, 0x0A, 0x10, 0x00, 0x00, 0x34, 0x5D, 0x0D };

          ////  // Not Cut
          //  byte[] a = new byte[] { 0x29, 0x29, 0x80, 0x00, 0x28, 0x37, 0x18, 0x86, 0x54, 0x12, 0x08, 0x03, 0x17, 0x35, 0x13, 0x01, 0x00, 0x32, 0x20, 0x88, 0x42, 0x60, 0x33, 0x00, 0x07, 0x00, 0x12, 0xFF, 0xFF, 0x00, 0x00, 0x02, 0xFC, 0x00, 0x00, 0x00, 0x0F, 0x64, 0x09, 0x06, 0x00, 0x00, 0x34, 0x4C, 0x0D };
            
          ////  //{ 0x29, 0x29, 0x80, 0x00, 0x28, 0x37, 0x18, 0x86, 0x54, 0x12, 0x07, 0x29, 0x15, 0x50, 0x56, 0x01, 0x00, 0x33, 0x38, 0x88, 0x42, 0x64, 0x73, 0x00, 0x00, 0x01, 0x69, 0xFF, 0xFF, 0x00, 0x00, 0x82, 0xFC, 0x00, 0x00, 0x00, 0x0F, 0x64, 0x0A, 0x12, 0x00, 0x00, 0x34, 0xFC, 0x0D };

            
          //// string trama = string.Empty;
          //// //StringBuilder sb = new StringBuilder(); 
          //// // foreach (byte b in m_arrByte)
          //// //{
          //// //    sb.AppendFormat("0x{0:X2},", b);
          //// //}

          //// // trama = sb.ToString();
          ////// trama = iTrackProtocol.GetProtocol(m_arrByte);       

          //// //double a1 = iTrackProtocol.GetCoordinate(m_arrByte, iTrackProtocol.MessageCoordinate.Latitude);
          //// //double a2 = iTrackProtocol.GetCoordinate(m_arrByte, iTrackProtocol.MessageCoordinate.Longitude);
          //// //trama = a1.ToString() + "  -  " + a2.ToString();
                       
          ////// Console.WriteLine(trama);

          //  string trama2 = iTrackProtocol.GetProtocol2(a);

          // Console.WriteLine(trama2);            

          //  Console.ReadLine();

            //Message Quere

            // check if queue exists, if not create it
            //MessageQueue msMq = null;
            //if (!MessageQueue.Exists(queueName))
            //{
            //    msMq = MessageQueue.Create(queueName);
            //}
            //else
            //{
            //    msMq = new MessageQueue(queueName);
            //}
            //try
            //{
            //    // msMq.Send("Sending data to MSMQ at " + DateTime.Now.ToString());
            //    Person p = new Person()
            //    {
            //        FirstName = "ITFunda",
            //        LastName = ".Com"
            //    };
            //    msMq.Send(p);
            //}
            //catch (MessageQueueException ee)
            //{
            //    Console.Write(ee.ToString());
            //}
            //catch (Exception eee)
            //{
            //    Console.Write(eee.ToString());
            //}
            //finally
            //{
            //    msMq.Close();
            //}
            //Console.WriteLine("Message sent ......");


            StringBuilder sb = new StringBuilder();

            string headerTable = "Código".PadRight(10) + "Descripción".PadRight(50) + "Cantidad".PadRight(8);
            sb.AppendLine(headerTable);

            Console.WriteLine(sb.ToString());
            Console.ReadKey();


        }

        public void SendSms()
        {

            SerialPort port = new SerialPort("COM19");

            port.BaudRate = 19200;
            port.Parity = Parity.None;
            port.DataBits = 8;
            port.StopBits = StopBits.One;
            port.Handshake = Handshake.RequestToSend;
            port.DtrEnable = true;
            port.RtsEnable = true;
            port.NewLine = Environment.NewLine;

            port.WriteLine("AT");
            port.WriteLine("AT+CMGF=1" + Environment.NewLine);
            port.WriteLine("AT+CMGS= " + "88661075" +Environment.NewLine);

            port.Open();
       


     //SMSPort.WriteLine("AT")
     //   'set command message format to text mode(1)
     //   SMSPort.WriteLine("AT+CMGF=1" & vbCrLf) 
     //   'set service center address (which varies for service providers (idea, airtel))
     //   SMSPort.WriteLine("AT+CSCA=""+919822078000""" & vbCrLf)             
     //   ' enter the mobile number whom you want to send the SMS
     //   SMSPort.WriteLine("AT+CMGS=  + TextBox1.text + " & vbCrLf) 
     //   _ContSMS = False
     //   SMSPort.WriteLine("+ TextBox1.text +" & vbCrLf & Chr(26)) 'SMS sending

        }

        //public bool sendMsg(SerialPort port, string PhoneNo, string Message)
        //{
        //    bool isSend = false;

        //    try
        //    {
        //        string recievedData = ExecCommand(port, "AT", 300, "No phone connected");
        //        recievedData = ExecCommand(port, "AT+CMGF=1", 300,
        //            "Failed to set message format.");
        //        String command = "AT+CMGS=\"" + PhoneNo + "\"";
        //        recievedData = ExecCommand(port, command, 300,
        //            "Failed to accept phoneNo");
        //        command = Message + char.ConvertFromUtf32(26) + "\r";
        //        recievedData = ExecCommand(port, command, 3000,
        //            "Failed to send message"); //3 seconds
        //        if (recievedData.EndsWith("\r\nOK\r\n"))
        //        {
        //            isSend = true;
        //        }
        //        else if (recievedData.Contains("ERROR"))
        //        {
        //            isSend = false;
        //        }
        //        return isSend;
        //    }
        //    catch (Exception ex)
        //    {
        //        throw new Exception(ex.Message);
        //    }
        //}

    }
}